﻿using System;
using System.Data;
using System.Windows.Forms;
//using static ProjectStudent.cvsTest;


namespace ProjectStudent
{
    public partial class StudentForm : Form
    {
        public StudentForm()
        {
            InitializeComponent();
        }
        public int studentID { get; set; }
        public StudentForm(DataRow row) : this()
        {
            if (row != null)
            {
                this.Text = "修改";
                studentID = Convert.ToInt32(row["StudentID"]);
                txtStudentNo.Text = row["StudentNo"].ToString().Trim();
                txtStudentName.Text = row["StudentName"].ToString();
                if (row["Gender"].ToString() == "男")
                {
                    rbtnMale.Checked = true;
                }
                else if(row["Gender"].ToString() == "女")
                {
                    rbtnFemale.Checked = true;
                }
                dtpBirthDate.Value = Convert.ToDateTime(row["BirthDate"]);
                dtpEnrollmentDate.Value = Convert.ToDateTime(row["EnrollmentDate"]);
                txtClassID.Text = row["ClassID"].ToString ();
                if (row["status"].ToString() == "在读")
                {
                    rbtnStudy.Checked = true;
                }
                else if(row["status"].ToString() == "毕业")
                {
                    rbtnGraduate.Checked = true;
                }
            }
            else
            {
                this.Text = "新增";
            }
        }

        public string studentNo => txtStudentNo.Text;
        public string studentName => txtStudentName.Text;
        public string gender => rbtnFemale.Checked ? rbtnFemale.Text : rbtnMale.Text;
        public string birthDate => dtpBirthDate.Value.ToString();
        public string enrollmentDate => dtpEnrollmentDate.Value.ToString();
        public string classID => txtClassID.Text;
        public string status => rbtnStudy.Checked ? rbtnStudy.Text : rbtnGraduate.Text;

       

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtClassID.Text) || !int.TryParse(txtClassID.Text, out int classId))
            {
                MessageBox.Show("班级ID必须为数字！");
                return;
            }
           
            this.DialogResult = DialogResult.OK;
        }

    }
}
